<?php

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;

class CauseController extends \App\Http\Controllers\AdminController {
    /**
     * 公告管理
     */
    public function index() {
        $causes = \App\Models\Cause::orderBy('id', 'desc')->get();
        $assign = compact('causes');
        return view('admin.cause.index', $assign);
    }
    /**
     * 添加公告
     * @param Request $request
     * @return type
     */
    public function add(Request $request) {
        if ($request->ajax()) {
            return \Illuminate\Support\Facades\Response::json(\App\Models\Cause::addCause($request));
        }
        return view('admin.cause.add');
    }
    /**
     * 删除公告
     */
    public function del($id) {
        $cause = \App\Models\Cause::find($id);
        if ($cause) {
            $cause->delete();
            $res = ['status'=> 1, 'info'=> "删除成功"];
        } else {
            $res = ['status'=> 0, 'info'=>'删除失败'];
        }
        return \Illuminate\Support\Facades\Response::json($res);
    }
}
